<%@ page import="java.util.List" %>

<script type="text/javascript">

	function showAddForm()
	{
		addContact.style.display = "block";
		showForm.value = "Cancel";
		showForm.onclick = function() {hideAddForm();};
	}
	
	function hideAddForm()
	{
		addContact.style.display = "none";
		showForm.value = "Add contact";
		showForm.onclick = function() {showAddForm();};
	}
	
// 	function displayActions(name)
// 	{
// 		document.getElementById("contactActions").style.visibility = "visible";
// 		document.getElementById("contactline"+name).onclick = function(){hideActions(name);};
// 	}
	
// 	function hideActions(name)
// 	{
// 		document.getElementById("contactActions").style.visibility = "hidden";
// 		document.getElementById("contactline"+name).onclick = function(){displayActions();};
// 	}
	
	function deleteContact()
	{
		var answer = confirm("Delete this contact?");
		if(answer){
			document.getElementById("deletelink").href = "http://www.google.com";
		}
	}
	
</script>
<h3>Contacts</h3>
<%
	List<String> list = (List<String>)request.getAttribute("contactlist");
	String currentGroup = Long.toString((Long)request.getAttribute("currentGroup"));
%>

<ul class="contactList">
	<% for (String s : list) { %>
	<li id="contactline"" onClick="displayActions()"><%=s%>
	<div id="contactActions">
		<a href="<%="SeeContact?mode=details&name="+s %>">See details</a>
		<a href="<%="SeeContact?mode=edit&name="+s %>">Edit contact</a>
		<a href="#" onClick="deleteContact(); return false">Delete</a>
	</div>
	</li>
	<% } %>
</ul>
<input type="button" name="showForm" value="Add contact" onClick="showAddForm()"/>
<form name="addContact" style="display:none" action="newContact.do" method="GET">
	<label>Name :</label>
	<input type="text" name="name"/><br/>
	<label>Surname :</label>
	<input type="text" name="surname"/><br/>
	<label>Phone :</label>
	<input type="text" name="phone"/><br/>
	<label>Email :</label>
	<input type="text" name="email"/><br/>
	<input type="hidden" name="group" value="<% out.print(currentGroup); %>"/>
	<br/>
	<input type="submit" value="Add"/>
</form>
